<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>登录页面</title>
	<link rel="stylesheet" href="css/common.css">
	<link rel="stylesheet" href="css/login.css">

	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
</head>

<body>
	<div class="nav">
		<div class="flag">
			<img src="image/face2.png" alt="logo">
			<div class="title">日程提醒</div>
		</div>

		<div class="page">
			<a href="login.html">登录</a>
		</div>
	</div>

	<div class="login_container">

		<div class="login_dialog">
			<div class="log_image">
				<img src="image/kangna_log2.png" alt="">

			</div>
			<table>
				<tr>
					<th colspan="2" class="denglu" style="vertical-align: bottom">注册</th>
				</tr>
				<tr>
					<td class="t1">用户名</td>
					<td><input type="text" id="username"></td>
				</tr>
				<tr>
					<td class="t1">密码</td>
					<td><input type="password" id="password"></td>
				</tr>
				<tr>
					<td class="t1">确认密码</td>
					<td><input type="password" id="password2"></td>
				</tr>
				<tr>
					<td class="t1">邮箱</td>
					<td><input type="text" id="email"></td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" value="提交" id="submit" onclick="reg()"></td>
				</tr>
			</table>
		</div>
	</div>
	<script>
		function reg() {
			// 1.校验参数
			var username = jQuery("#username");
			var password = jQuery("#password");
			var password2 = jQuery("#password2");
			var email = jQuery("#email");
			if (username.val().trim() == "") {
				alert("请输入用户名!");
				usename.focus();
				return false;
			}
			if (password.val().trim() == "") {
				alert("请输入密码!");
				password.focus();
				return false;
			}
			if (password2.val().trim() == "") {
				alert("请确认密码!");
				password2.focus();
				return false;
			}
			if (password2.val().trim() != password.val().trim()) {
				alert("两次密码不一致!");
				return false;
			}
			if (email.val().trim() == "") {
				alert("请输入邮箱!");
				email.focus();
				return false;
			}
			// 2.将参数提交给后端
			jQuery.ajax({
				url: "/user/reg",
				type: "POST",
				data: {
					"username": username.val().trim(),
					"password": password.val().trim(),
					"email": email.val().trim()
				},
				success: function (res) {
					// 3.将结果返回给用户
					if (res.code == 0) {
						// 注册成功
						alert("注册成功!");
						// 跳转到登录页
						location.href = "login.html";
					} else {
						// 注册失败
						alert("抱歉注册失败!" + res.meg);
					}
				}
			});
		}
	</script>
</body>

</html>